package com.zhangkeyou.map.mapweb.controller;

import com.zhangkeyou.map.mapweb.domain.entity.MapData;
import com.zhangkeyou.map.mapweb.domain.entity.Status;
import com.zhangkeyou.map.mapweb.service.MapDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/mapdata")
public class MapDataController {

    @Autowired
    private MapDataService mapDataService;

    @GetMapping
    public Status mapDataService(){
        List<MapData> mapDataList = mapDataService.getMapData();
        return new Status<>(200,mapDataList,"success");
    }

    @PostMapping
    public Status insertMapData(@RequestBody MapData mapData){
        String mapId = mapDataService.insertMapData(mapData);
        return new Status<>(200,mapId,"success");
    }

    @DeleteMapping
    public Status deleteMapData(@RequestBody String id){
        Long count = mapDataService.deleteMapData(id);
        return new Status(200,count,"success");
    }

    @PostMapping("/convert/gps84togcj02")
    public Status gps84togcj02(@RequestBody String rings) throws Exception {
        Object ringConverted = mapDataService.convertGps84ToGcj02(rings);
        return new Status<>(200,ringConverted,"success");
    }
    @PostMapping("/convert/gcj02togps84")
    public Status gcj02togps84(@RequestBody String rings) throws Exception {
        Object ringConverted = mapDataService.convertGcj02ToGps84(rings);
        return new Status<>(200,ringConverted,"success");
    }

    @PutMapping("/updateDate")
    public Status updateDate(@RequestBody MapData mapData){
        Object result = mapDataService.updateDate(mapData);
        return new Status(result);
    }

    @PutMapping("/addPath")
    public Status addPath(@RequestBody MapData mapData){
        Object result = mapDataService.addPath(mapData);
        return new Status(result);
    }
}
